import {Component, inject, Input, OnInit} from '@angular/core';
import {FormBuilder, FormsModule, ReactiveFormsModule} from '@angular/forms';

import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzDatePickerModule } from 'ng-zorro-antd/date-picker';
import { NzFormModule } from 'ng-zorro-antd/form';
import { NzTimePickerModule } from 'ng-zorro-antd/time-picker';
import {NzOptionComponent, NzSelectComponent} from 'ng-zorro-antd/select';
import {NzAutosizeDirective, NzInputDirective} from 'ng-zorro-antd/input';
import {CamundaService} from '../../../services/camunda.service';
import {NzCardComponent} from 'ng-zorro-antd/card';
import {NzTableCellDirective, NzTableComponent, NzTbodyComponent, NzTrDirective} from 'ng-zorro-antd/table';
import {NzSpaceComponent, NzSpaceItemDirective} from 'ng-zorro-antd/space';
import {NgForOf} from '@angular/common';
import {NzMessageService} from 'ng-zorro-antd/message';

@Component({
  selector: 'app-ask-for-level-promoter',
  standalone: true,
  imports: [ReactiveFormsModule, NzButtonModule, NzDatePickerModule, NzFormModule, NzTimePickerModule, NzOptionComponent, NzSelectComponent, NzInputDirective, NzCardComponent, NzTableCellDirective, NzTbodyComponent, NzTrDirective, NzAutosizeDirective, NzSpaceComponent, NzSpaceItemDirective, FormsModule, NzTableComponent, NgForOf],
  templateUrl: './ask-for-level-promoter.component.html',
  styleUrl: './ask-for-level-promoter.component.css'
})
export class AskForLevelPromoterComponent implements OnInit{
  constructor(private camundaService: CamundaService,
              private messageService: NzMessageService) {
  }

  //从父层传过来的 taskId
  @Input() taskId:String = "";

  //任务相关信息，用来回显页面
  taskMessage = {
    startTime: "",
    instanceId: "",
    processName: "",
    variables: {
      "starter":"",
      "reason":"",
      "rangePicker": [],
      "type": ""
    },
    nodes:<any>[]
  }

  currentOpinion= "";

  //表单数据
  formData = {
    "starter":"",
    "reason":"",
    "rangePicker": [],
    "type": ""
  }

  ngOnInit(): void {
    this.camundaService.task_message(this.taskId).subscribe(res => {
      this.taskMessage = res;
      this.formData = this.taskMessage.variables
    })
  }

  //重新发起按钮
  reStart(): void{
    this.camundaService.reStart_starter(this.taskId, this.formData).subscribe()
    this.messageService.create("success", "流程已重新发起");
  }

  //驳回按钮
  revoke(): void{
    this.camundaService.revoke_starter(this.taskId).subscribe()
    this.messageService.create("success", "流程已撤销")
  }
}
